package com.ruoyi.web.controller.lwpq;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqSybx;
import com.ruoyi.lwpq.service.ILwpqSybxService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sybxController
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@Controller
@RequestMapping("/lwpq/sybx")
public class LwpqSybxController extends BaseController
{
    private String prefix = "lwpq/sybx";

    @Autowired
    private ILwpqSybxService lwpqSybxService;

    @RequiresPermissions("lwpq:sybx:view")
    @GetMapping()
    public String sybx()
    {
        return prefix + "/sybx";
    }

    /**
     * 查询sybx列表
     */
    @RequiresPermissions("lwpq:sybx:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqSybx lwpqSybx)
    {
        startPage();
        lwpqSybx.setCreateBy(getLoginName());
        List<LwpqSybx> list = lwpqSybxService.selectLwpqSybxList(lwpqSybx);
        return getDataTable(list);
    }

    /**
     * 导出sybx列表
     */
    @RequiresPermissions("lwpq:sybx:export")
    @Log(title = "sybx", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqSybx lwpqSybx)
    {
        List<LwpqSybx> list = lwpqSybxService.selectLwpqSybxList(lwpqSybx);
        ExcelUtil<LwpqSybx> util = new ExcelUtil<LwpqSybx>(LwpqSybx.class);
        return util.exportExcel(list, "sybx数据");
    }

    /**
     * 新增sybx
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存sybx
     */
    @RequiresPermissions("lwpq:sybx:add")
    @Log(title = "sybx", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqSybx lwpqSybx)
    {
        lwpqSybx.setCreateBy(getLoginName());
        return toAjax(lwpqSybxService.insertLwpqSybx(lwpqSybx));
    }

    /**
     * 修改sybx
     */
    @RequiresPermissions("lwpq:sybx:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqSybx lwpqSybx = lwpqSybxService.selectLwpqSybxById(id);
        mmap.put("lwpqSybx", lwpqSybx);
        return prefix + "/edit";
    }

    /**
     * 修改保存sybx
     */
    @RequiresPermissions("lwpq:sybx:edit")
    @Log(title = "sybx", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqSybx lwpqSybx)
    {
        lwpqSybx.setUpdateBy(getLoginName());
        return toAjax(lwpqSybxService.updateLwpqSybx(lwpqSybx));
    }

    /**
     * 删除sybx
     */
    @RequiresPermissions("lwpq:sybx:remove")
    @Log(title = "sybx", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqSybxService.deleteLwpqSybxByIds(ids));
    }
}
